/**
 * FileName: LoadParkingLotConfiguration
 * Author:   Leopold
 * Date:     2018/9/26 11:20
 * Description:
 * History:
 */
package cn.mcsys.myadmin.common.config;

import java.awt.geom.Point2D;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class LoadParkingLotConfiguration {

    public static final String BPIANQU = "bpianqu";
    public static final String QIANWU = "qianwu";
    public static final String JINTAISHI = "jintaishi";
    public static final String GAOLANGANG = "gaolangang";
    public static final String SAICHECHANG = "saichechang";
    public static final String YINLONG = "yinlong";


    public static Map<String,List<Point2D.Double>> parkingLotMap = new HashMap<>();

    static {
        InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("parking-lot-lon-lat.properties");

        Properties properties = new Properties();

        try {
            properties.load(in);
//        B片区
            List<Point2D.Double> bpianqu = createridePoint2D(properties, BPIANQU);
//        乾务停车场
            List<Point2D.Double> qianwu = createridePoint2D(properties, QIANWU);
//        金台寺
            List<Point2D.Double> jintaishi = createridePoint2D(properties, JINTAISHI);
//        高栏港
            List<Point2D.Double> gaolangang = createridePoint2D(properties, GAOLANGANG);
//        国际saichechang
            List<Point2D.Double> saichechang = createridePoint2D(properties, SAICHECHANG);
//        银隆停车场
            List<Point2D.Double> yinlong = createridePoint2D(properties, YINLONG);

            parkingLotMap.put("P6银隆停车场",yinlong);
            parkingLotMap.put("P7B片区停车场",bpianqu);
            parkingLotMap.put("P8乾务停车场",qianwu);
            parkingLotMap.put("P9金台寺停车场",jintaishi);
            parkingLotMap.put("P10高栏港停车场",gaolangang);
            parkingLotMap.put("P11赛车场停车场",saichechang);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static Double[] parseLonLat(String lonlat){
        String[] lls = lonlat.split(",");
        Double[] lld = new Double[2];
        for (int i = 0; i < lls.length; i++) {
            lld[i] = Double.valueOf(lls[i]);
        }
        return lld;
    }

    private static List<Point2D.Double> createridePoint2D(Properties properties,String pointName){
        List<Point2D.Double> points = new ArrayList<>();
        Double[] point1 = parseLonLat(properties.getProperty(pointName+"-1"));
        Double[] point2 = parseLonLat(properties.getProperty(pointName+"-2"));
        Double[] point3 = parseLonLat(properties.getProperty(pointName+"-3"));
        Double[] point4 = parseLonLat(properties.getProperty(pointName+"-4"));
        points.add(new Point2D.Double(point1[0],point1[1]));
        points.add(new Point2D.Double(point2[0],point2[1]));
        points.add(new Point2D.Double(point3[0],point3[1]));
        points.add(new Point2D.Double(point4[0],point4[1]));
        return points;
    }

}
